package com.my.home.common.utils;

import org.springframework.web.util.HtmlUtils;

import java.beans.PropertyEditorSupport;

/**
 * Created by Al Sah-him on 2018/7/5.
 */
public class CustomStringEditor extends PropertyEditorSupport {

    @Override
    public String getAsText() {
        Object value=getValue();
        return value != null ? value.toString() : "";
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if(text == null){
            setValue(null);
        }else {
            setValue(HtmlUtils.htmlEscape(text));
        }
    }
}
